package com.youth.youthservice.controller;


import com.youth.commonutils.R;
import com.youth.youthservice.entity.vo.annoVo.AnnoUserQuery;
import com.youth.youthservice.entity.vo.annoVo.AnnounceQuery;
import com.youth.youthservice.entity.vo.annoVo.AnnouncementVo;
import com.youth.youthservice.service.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author huangqicai
 * @since 2023-03-22
 */
@Api(description = "公告模块")
@RestController
@RequestMapping("/eduservice/announcement")
// 使用nginx是需要使用@CrossOrigin解决跨域问题的，现在使用gateway网关替代  /*解决跨域问题*/
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    @ApiOperation(value = "发布公告")
    @PostMapping("/publish")
    public R publish(@RequestBody AnnouncementVo announcementvo) {
        return announcementService.publish(announcementvo);
    }


    @ApiOperation(value = "查询选课学生的信息")
    @GetMapping("/selectCourseStu")
    public R selectCourseStu() {
        return announcementService.selectCourseStu();
    }


    @ApiOperation(value = "分页条件查询公告列表")
    @PostMapping("/selectPage/{current}/{limit}")
    public R selectPage(@PathVariable(value = "current") long current,
                        @PathVariable(value = "limit") long limit,
                        @RequestBody AnnounceQuery announceQuery) {
        return announcementService.selectPage(current, limit, announceQuery);
    }

    @ApiOperation(value = "删除公告执行的方法")
    @GetMapping("/deleteAnno/{annoId}")
    public R deleteAnno(@PathVariable(value = "annoId") String annoId) {
        return announcementService.deleteAnno(annoId);
    }

    @ApiOperation(value = "根据公告id查看公告详细信息")
    @GetMapping("/selectInfo/{annoId}")
    public R selectInfo(@PathVariable(value = "annoId") String annoId) {
        return announcementService.selectInfo(annoId);
    }


    @ApiOperation(value = "根据公告id查询公告对象的集合-(条件查询)")
    @PostMapping("/selectUsers/{annoId}")
    public R selectUsers(@PathVariable(value = "annoId") String annoId,
                         @RequestBody AnnoUserQuery annoUserQuery) {
        return announcementService.selectUsers(annoId, annoUserQuery);
    }

    @ApiOperation(value = "根据手机号发送短信，提醒用户")
    @PostMapping("/sendMsmToStu/{phone}")
    public R sendMsmToStu(@PathVariable(value = "phone") String phone) {
        return announcementService.sendMsmToStu(phone);
    }

    @ApiOperation(value = "更新公告信息执行的方法")
    @PostMapping("/updateAnno/{annoId}")
    public R updateAnno(@PathVariable(value = "annoId") String annoId,
                        @RequestBody AnnouncementVo announcementVo) {
        return announcementService.updateAnno(annoId, announcementVo);
    }

    /*--------------------------前台的相关api--------------------------------*/
    @ApiOperation(value = "根据用户id得到公告列表-分页条件查询")
    @PostMapping("/selectListAnno/{current}/{limit}")
    public R selectListAnno(
            @PathVariable(value = "current") long current,
            @PathVariable(value = "limit") long limit,
            @RequestBody AnnounceQuery announceQuery,
            HttpServletRequest request) {
        return announcementService.selectListAnno(current, limit, announceQuery, request);
    }


}

